08_K_Means_Clustering
Tags: #◇CSINTSY #◇Computational Thinking #◇Computer Science #◇Artificial Intelligence #◇Machine Learning #◇Intelligent Systems #◇Probability #◇Data Analysis
◇Overview
K-Means Clustering is an unsupervised learning algorithm that partitions a dataset into distinct, non-overlapping subgroups (clusters).
◇Details / Theory
8. K-Means Clustering Reviewer
◇Overview
K-Means Clustering is an unsupervised learning algorithm that partitions a dataset into distinct, non-overlapping subgroups (clusters).
◇Goal
To group similar data points together such that:
- Data points within the same cluster are as similar as possible (minimize intra-cluster distance).
- Data points in different clusters are as different as possible (maximize inter-cluster distance).
◇Algorithm Steps
- Initialize: Choose (the number of clusters). Select random data points as initial centroids (center of the cluster).
- Assign: For every data point in the dataset, calculate its distance to each centroid. Assign the point to the cluster with the nearest centroid.
- Update: Recalculate the new centroids. The new centroid of a cluster is the mean (average) position of all points assigned to that cluster.
- Repeat: Repeat steps 2 and 3 until convergence:
Centroids do not change position.
Or points do not change clusters.
Or a maximum number of iterations is reached.
◇Solved Example: 1-Dimensional Clustering
Dataset: Points on a line: .
K = 2.
Iteration 1:
- Initialize Centroids: Randomly pick and .
- Assign Points:
Point 2: (Near ), . Cluster 1.
Point 3: (Near ), . Cluster 1.
Point 10: , (Near ). Cluster 2.
Point 11: , (Near ). Cluster 2.
Point 12: , (Near ). Cluster 2.
Clusters: , . - Update Centroids:
New .
New .
Iteration 2:
- Assign Points (using new centroids 2.5 and 11):
Point 2: , . Cluster 1.
Point 3: , . Cluster 1.
Point 10: , . Cluster 2.
Point 11: , . Cluster 2.
Point 12: , . Cluster 2. - Check Convergence:
Clusters are still and .
No change in assignment. Converged!
Final Clusters: and .
◇Distance Measures
How do we measure "nearest"?
Euclidean Distance: The straight-line distance between two points. Most common.
Manhattan Distance: The sum of absolute differences. Used for grid-like paths.
◇Choosing K (Elbow Method)
How do we know the best number of clusters ()?
- Run K-Means for a range of values (e.g., 1 to 10).
- Calculate the Inertia (Sum of Squared Errors - SSE) for each . This measures how spread out the clusters are (lower is better).
- Plot Inertia vs. .
- Look for the "Elbow": The point where the inertia starts decreasing slowly. This is usually the optimal .
◇Common Pitfalls
Sensitive to initial centroid placement — different initializations can yield different clusters. Assuming K-Means works well with non-spherical or unequal-variance clusters — it assumes roughly equal-sized, spherical clusters. Choosing arbitrarily — use the Elbow Method (plot SSE vs. ) to find a reasonable number of clusters.
◇Summary
TL;DR — K-Means iteratively assigns points to the nearest centroid (using Euclidean or Manhattan distance) and updates centroids as cluster means until convergence. Use the Elbow Method to select .
◇Links
Related: Source / Reference:
Made by 2ru17
Please contact me through discord or my the university email for any problems regarding the reviewer. Thanks!
◇References & Navigation
- Previous Topic: ◇Naive Bayes
- Next Topic: ◇MDP
- Related Notes: ◇K-Means Clustering
ACTIVE RECALL VERIFICATION
Select an answer to verify conceptual comprehension and reveal the technical rationale.
K-Means Clustering is primarily classified as what type of algorithm?
What is the main objective of K-Means Clustering regarding distances?
In the K-Means algorithm, what does the value represent?
During the "Update" step of the K-Means algorithm, how is the new centroid calculated?
Which condition does NOT typically signify the convergence of the K-Means algorithm?
Which distance metric calculates the straight-line distance between two points?
Which method is commonly used to determine the optimal number of clusters ()?
What does "Inertia" (Sum of Squared Errors) measure in K-Means clustering?
What is a known pitfall of the K-Means Clustering algorithm?
When using the Elbow Method, what are you looking for on the plot of Inertia vs. ?